package com.service.thirddatacenter.hpool.controller;

import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.thirddatacenter.chiaexplorer.client.ChiaExplorerClient;
import com.service.thirddatacenter.chiaexplorer.service.BlockChainRecordService;
import com.service.thirddatacenter.hpool.client.HPoolClient;
import com.service.thirddatacenter.hpool.service.AccountMinerService;
import com.service.thirddatacenter.hpool.service.AccountShareService;
import com.service.thirddatacenter.hpool.service.MiningRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("hpool/")
public class HPoolController extends BaseController {

    @Autowired
    private ChiaExplorerClient chiaExplorerClient;

    @Autowired
    private BlockChainRecordService blockChainRecordService;

    @Autowired
    private AccountMinerService accountMinerService;

    @Autowired
    private AccountShareService accountShareService;

    @Autowired
    private MiningRecordService miningRecordService;

    @Autowired
    private HPoolClient hPoolClient;

    @GetMapping("hello-world")
    public BaseResponse helloWorld() {
        return successBaseResponse("hello world");
    }

    @GetMapping("blockchain-summary")
    public BaseResponse getBlockchainSummary() {
        blockChainRecordService.createBlockChain();
        return successQueryOneResponse(null);
//        return successQueryOneResponse(chiaExplorerClient.getBlockchainSummary());
    }

    @GetMapping("mining-income-record")
    public BaseResponse getMiningIncomeRecord() {

        /*String cookie = "lang=zh; _ga=GA1.2.35167718.1622708416; MEIQIA_TRACK_ID=1tQjsq8NPT5g9OFLRT4mbsoTRhg; aliyungf_tc=68a3d384fbb48713033906c4c563cc77090aa0ded5cb42598a91ab92cd070e30; auth_token=eyJldCI6MTYyNDMyNzExNywiZ2lkIjo2NCwidWlkIjozNjc3NzZ9.SczdCcIQZ/TAcx2G5rhmE20VmCrq6qQYPgHmkd2ngoJaUh44ZbcFCWS0HZCI/JIHwHyDopxjBUDOaCgS8mY2Lw0yRvD+NvkFB4Tlkz1MGIf6HtYa/wZVzGOVAv7dDA8r+BaDq0E6JZFux16459zOr3UplEXAemYjcY3UeHpvLQck3IUNmKJknOPW9tlbzfPBf41QCYGUkgM3P/nm9TjSGFwKWBBQW4iZmVWIMv8ZPxYnxxcm04C8QgPXzDEif+ysxDug8PKNV5+2XsvQLdkGeaiWFIHro4O6fMjePNIR5OEGgnH7bhOFK7Vz7DblIav32tULpDlf1qEBsV6Y9UwZyw==";
        HPoolResponse<HPoolPageResponse<List<MiningIncomeRecord>>> result = hPoolClient.pageMiningIncomeRecord("zh", "chia", 0, 1, cookie);
        if(result.getCode() == 200){
            return successQueryOneResponse(result.getData());
        }*/

        miningRecordService.syncMiningRecord();

        return successBaseResponse();
//        return successQueryOneResponse(chiaExplorerService.getBlockchainSummary());
    }

    @GetMapping("page-miner")
    public BaseResponse pageMiner() {
        accountMinerService.syncMinerFromPlatform();
        return successBaseResponse();
//        return successQueryOneResponse(chiaExplorerService.getBlockchainSummary());
    }

    @GetMapping("page-share")
    public BaseResponse pageShare() {

        accountShareService.syncAccountShare();
        return successBaseResponse();
//        return successQueryOneResponse(chiaExplorerService.getBlockchainSummary());
    }




}
